<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>源计划-赛事官网</title>
    <!-- 引入vue -->
    <script src="utils/vue.js"></script>
    <!-- 引入axios -->
    <script src="utils/axios.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body>
<div id="app">
    <el-upload
            class="avatar-uploader"
            action="/upload?dir=img"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
        <img v-if="imageUrl" :src="imageUrl" class="avatar">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
    </el-upload>
    <input type="text" v-model:value="username">
    <input type="password" v-model:value="password">
    <button  @click.prevent="login">登录</button>
</div>
<script>
    var vue = new Vue({
        el:"#app",
        data() {
            return {
                imageUrl: '',
                username:'',
                password:''
            };
        },
        methods: {
            handleAvatarSuccess(res, file) {
                this.imageUrl = URL.createObjectURL(file.raw);
            },
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isJPG) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            },
            login(){
                let params = new URLSearchParams();
                params.append("username",this.username);
                params.append("password",this.password);
                axios.post("http://127.0.0.1:53809/user/login",params).then(res=>{
                    this.$message(res.data.msg);
                })

            }
        }
    });
</script>
</body>
<style>
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }
    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }
    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
</style>
</html>